package CollectionDemo;

import java.util.ArrayList;
import java.util.Iterator;

public class Demo3 {
    public static void main(String[] args) {
        ArrayList<Student>list =new ArrayList<>();
        Student s1 = new Student("王思聪",33);
        Student s2 = new Student("吴亦凡",33);
        Student s3 = new Student("张子枫",19);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        //迭代器
        Iterator<Student> it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

        System.out.println("------------------");

        //增强for
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
